// constSpringJointPortSet.cpp: implementation of the ConstSpringJointPortSet class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "constSpringJointPortSet.h"
#include "DBConnectionManager.h"
#include "ProductCatalogManager.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

using namespace JointSystem;
using namespace DAWrapper;
ConstSpringJointPortSet::ConstSpringJointPortSet()
{

}

ConstSpringJointPortSet::~ConstSpringJointPortSet()
{

}

BOOL ConstSpringJointPortSet::GetConstSpringJointPort(DOUBLE dbForce, const CString& strPartID)
{
	ASSERT(!strPartID.IsEmpty());

	GetTables();
	CString strSql;
	strSql.Format(_T("select * from %s where Pmax >= %g and CustomID = '%s' order by Pmax"),
		m_theTables.GetAt(0), dbForce, strPartID);

	try
	{
		CString strSource;
		strSource = ProductCatalogManager::Instance()->GetProductCatalog(this->GetDataStandard())->DataSourceURI();
		ASSERT(!strSource.IsEmpty());
		_ConnectionPtr* pcon = DBConnectionManager::Instance()->GetConnectionPtrByUri(strSource);
		ASSERT(pcon != NULL);
		
		m_rs = (*pcon)->Execute(_bstr_t(strSql), NULL, adCmdText);
	}
	CATCH_COM_ERROR(m_rs, FALSE);
	
	return TRUE;
}

BOOL ConstSpringJointPortSet::GetTables()
{
	StandardOfConstSpring* pSpring = this->GetStandardOfConstSpring();
	ASSERT(pSpring);
	ASSERT(!pSpring->GetDiameterOfConstSpringTable().IsEmpty());
	this->m_theTables.Add(pSpring->GetDiameterOfConstSpringTable());
	return TRUE;
}